package com.xxxy.dongyexuan.action;

import com.xxxy.dongyexuan.mapper.IFlowMapper;
import com.xxxy.dongyexuan.mapper.ILevelMapper;
import com.xxxy.dongyexuan.po.Flow;
import com.xxxy.dongyexuan.po.Level;
import com.xxxy.dongyexuan.po.PageBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
public class FlowAction {

    @Autowired
    private IFlowMapper mapper;


    //分页查询
    @GetMapping("/flow/{pagenow}/{pagesize}")
    public PageBean findByPage(@PathVariable("pagenow") int pagenow, @PathVariable("pagesize") int pagesize){
        int from =(pagenow-1)*pagesize;//开始条数
        int total = this.mapper.getcount();//总条数
        int pages =(total-1)/pagesize+1;//计算总页数
        List data = this.mapper.findByPage(from,pagesize);
        PageBean pageBean = new PageBean();
        pageBean.setPages(pages);
        pageBean.setPagenow(pagenow);
        pageBean.setPagesize(pagesize);
        pageBean.setTotal(total);
        pageBean.setData(data);
        return pageBean;
    }



    //查询所有
    @GetMapping("/flow")
    public List<Flow> findAll(){
        List<Flow> list = this.mapper.findAll();
        return list;
    }

    //根据员工号查询
    @GetMapping("/flow/{fid}")
    public Flow findById(@PathVariable("fid") int fid){
        Flow flow = this.mapper.findById(fid);
        return flow;
    }

    //增加
    @PostMapping("/flow")
    public int save(Flow flow){
        int result = this.mapper.save(flow);
        return result;
    }

    //修改
    @PutMapping("/flow")
    public int update(Flow flow){
        int result = this.mapper.merge(flow);
        return result;
    }

    //删除
    @DeleteMapping("/flow/{fid}")
    public int delete(@PathVariable("fid") int fid){
        int result = this.mapper.delete(fid);
        return result;
    }
}